<template>
  <div class="app-container">
    <div class="search-container">
      <el-form :model="searchParam" :inline="true">
        <SearchFormEsm
          equipType="input"
          :data="searchParam"
          @change-search="handleSearchChange"
          @start-search="handleStartSearch"
        />
        <!-- <el-form-item label="位置">
          <el-input
            v-model="searchParam.locationId"
            placeholder="请输入位置"
            clearable
            @keyup.enter="search"
          />
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="search">
            <i-ep-search />
            搜索
          </el-button>
          <el-button @click="reset">
            <i-ep-refresh />
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        :maxHeight="tableHeight"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          label="工序"
          prop="processCode"
          min-width="120"
          align="center"
          show-overflow-tooltip
        />
        <el-table-column
          label="生产线"
          prop="processEquipCode"
          min-width="130"
          align="center"
          show-overflow-tooltip
        />
        <el-table-column
          label="设备"
          prop="equipName"
          min-width="150"
          align="center"
          show-overflow-tooltip
        />
        <!-- <el-table-column
          label="设备编号"
          prop="equipCode"
          min-width="150"
          align="center"
          show-overflow-tooltip
        /> -->
        <el-table-column
          label="位置"
          prop="locationId"
          min-width="120"
          show-overflow-tooltip
          align="center"
        >
          <template #default="scope">
            {{ scope.row.locationName }}
          </template>
        </el-table-column>
        <el-table-column
          label="备注"
          prop="remarks"
          min-width="150"
          align="left"
          show-overflow-tooltip
        />
        <el-table-column fixed="right" label="操作" width="60" align="center">
          <template #default="scope">
            <el-tooltip
              :hide-after="0"
              effect="light"
              content="报警设置"
              placement="top"
              align="center"
            >
              <el-button
                type="primary"
                size="small"
                link
                @click="openAlarmSettings(scope.row)"
              >
                <i-ep-setting style="margin-right: 0px" />
              </el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        :background="true"
        :current-page="pageable.pageNum"
        :page-size="pageable.pageSize"
        :page-sizes="[10, 25, 50, 100]"
        :total="pageable.total"
        layout="total, sizes, prev, pager, next, jumper"
        class="mt-[20px]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>

<script setup lang="ts">
import {
  useTable,
  useDownload,
  useDictionary,
  useComputeTableHeight,
} from "@/utils/useTable";
import request from "@/utils/request";
import { useRouter } from "vue-router";
import { ArrowDown } from "@element-plus/icons-vue";
import SearchFormEsm from "@/views/equ/esm/common/SearchFormEsm.vue";

defineOptions({
  name: "EQUESMDEVICEALARMRULE",
  inheritAttrs: false,
});

// --------------------------------------------------------------------------------------------------------组件 开始
// 处理传回数据
const handleSearchChange = (data: any) => {
  Object.assign(searchParam.value, data);
  // 可执行字段相关的特定逻辑
};
const handleStartSearch = (data: any) => {
  Object.assign(searchParam.value, data);
  search();
};
// --------------------------------------------------------------------------------------------------------组件 结束

let router = useRouter();
// 请求参数
const requestApi = "/iotadmin/scaequipinfo/queryByPage";

// 是否需要分页
const pagination = true;

const initParam = {};

// 初始化搜索参数数据
const searchParamInit = {
  processCode: "", // 工序编号
  processId: "", // 工序id
  equipCode: "", // 设备编号
  equipId: "", // 设备id
  equipName: "", // 设备名称
  processEquipId: "", // 生产设备id
};

const deleteParam = {
  api: "/iotadmin/scaequipinfo/delete",
  data: {},
};

// 数据请求错误后处理
function requestError() {}

// 定义tableHeight, 将计算注入dataCallBack回调中
const tableHeight = ref();
function dataCallBack(data: any) {
  setTimeout(() => {
    tableHeight.value = useComputeTableHeight();
  }, 100);
  return data;
}

// 表格操作 Hooks
const {
  tableData,
  pageable,
  searchParam,
  ids,
  getTableList,
  search,
  reset,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  handleTableDelete,
  loading,
}: any = useTable(
  requestApi,
  initParam,
  searchParamInit,
  pagination,
  dataCallBack,
  requestError,
  deleteParam
);

// 点击报警设置
const openAlarmSettings = (row: any) => {
  router.push({
    path: "/equ/esm/deviceAlarmSettings",
    query: {
      id: row.id,
    },
  });
};
onMounted(() => {
  getTableList();
});
</script>
<style lang="scss" scoped>
:deep(.el-button:focus-visible) {
  outline: none;
}
</style>
